package com.hzb.springcloud.controller;

import com.hzb.springcloud.entities.CommonResult;
import com.hzb.springcloud.entities.Payment;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;
import java.util.Calendar;
import java.util.Date;

/**
 * @version v1.0
 * @ProjectName: cloud2020
 * @ClassName: OrderController
 * @Description: TODO(一句话描述该类的功能)
 * @Author: huangZB
 * @Date: 2020/3/12 18:22
 */
@RestController
public class OrderController {

    private static final String PAYMENT_URL = "http://localhost:8001";

    @Resource
    private RestTemplate restTemplate;

    /**
     * @Title:
     * @Description: TODO(这里用一句话描述这个方法的作用)
     * @param @param
     * @return @return
     * @author huangZB
     * @throws
     * @date
     */
    @RequestMapping(value = "/consumer/payment/creat")
    public CommonResult creat(Payment payment){


        return restTemplate.postForObject(PAYMENT_URL+"/payment/creat",payment,CommonResult.class);
    }

    /**
     * @Title:
     * @Description: TODO(这里用一句话描述这个方法的作用)
     * @param @param
     * @return @return
     * @author huangZB
     * @throws
     * @date
     */
    @RequestMapping(value = "/consumer/payment/getPaymentById")
    public CommonResult getPaymentById(String  id){

        return restTemplate.postForObject(PAYMENT_URL+"/payment/getPaymentById?id="+id,id,CommonResult.class);
    }


    // ====================> zipkin+sleuth
    @GetMapping("/consumer/payment/zipkin")
    public String paymentZipkin()
    {
        String result = restTemplate.getForObject("http://localhost:8001"+"/payment/zipkin/", String.class);
        return result;
    }
}
